from pydantic import BaseModel, Field
from typing import List, Optional, Any
from datetime import datetime

class BaseGoods(BaseModel):
    name: Optional[str] = Field("",example="商品名称1")
    name_small: Optional[str] = Field("", example="副标题1")
    tags: Optional[str] = Field("", description="标签")
    brand_id: Optional[int] = Field(0)
    cover: Optional[str] = Field("", example="封面")
    banners: Optional[str] = Field("")
    contents: Optional[str] = Field("")
    category_id: Optional[int] = Field(0)
    info_goods: Optional[str] = Field("")
    info_after: Optional[str] = Field("")
    sku: Optional[str] = Field("")
    is_level: Optional[bool] = False
    is_level_type: Optional[int] = Field(0)
    is_hot: Optional[bool] = False
    is_hot_date: Optional[datetime]
    is_on: Optional[bool] = False
    is_on_date: Optional[datetime]
    is_off: Optional[bool] = False
    is_off_date: Optional[datetime]
    is_buy: Optional[bool] = False
    is_buy_days: Optional[int] = Field(0)
    is_buy_nums: Optional[int] = Field(0)
    is_low: Optional[bool] = False
    is_low_nums: Optional[int] = Field(0)
    is_buy_level: Optional[bool] = False
    is_buy_level_roles: Optional[str] = Field("")
    is_read: Optional[bool] = False
    is_read_roles: Optional[str] = Field("")
    is_select_user: Optional[bool] = False
    is_select_user_users: Optional[str] = Field("")
    is_share: Optional[bool] = True
    is_seven_day: Optional[bool] = True
    grow_id: Optional[int] = Field(0)
    order: Optional[int] = Field(0)
    desc: Optional[str] = Field("")
    contact_goods: Optional[str] = Field("")
    state: Optional[bool] = True
    express_id: Optional[int] = Field(0)
    get_deposit: Optional[int] = Field(0)
    get_deposit_max: Optional[int] = Field(0)
    get_integral: Optional[int] = Field(0)
    get_coupons: Optional[int] = Field(0)
    type: Optional[int] = Field(1)
    is_buckling: Optional[int] = Field(0)
    get_level_integral: Optional[int] = Field(0)
    giver_integral: Optional[int] = Field(0)
    giver_level_integral: Optional[int] = Field(0)
    giver_coupons: Optional[int] = Field(0)
    giver_deposit_max: Optional[int] = Field(0)
    goods_id : Optional[int] = Field(0)
    sku_id : Optional[int] = Field(0)
    giver_goods_id : Optional[int] = Field(0)
    giver_sku_id : Optional[int] = Field(0)
    rebate : Optional[int] = Field(0)
    input_cps: float = Field(0.00)
    operate_cps: float = Field(0.00)
    space_id: Optional[list] = None


class GoodsCreate(BaseGoods):
    banners: Optional[list] = None
    contents: Optional[list] = None
    info_goods: Optional[list] = None
    info_after: Optional[list] = None
    sku: Optional[list] = None
    is_buy_level_roles: Optional[list] = None
    is_read_roles: Optional[list] = None
    is_select_user_users: Optional[list] = None
    contact_goods: Optional[list] = None
    is_hot_date: Optional[str] = None
    is_on_date: Optional[str] = None
    is_off_date: Optional[str] = None
    tags: Optional[list] = None


class GoodsUpdate(BaseGoods):
    id: int
    banners: Optional[list] = None
    contents: Optional[list] = None
    info_goods: Optional[list] = None
    info_after: Optional[list] = None
    sku: Optional[list] = None
    is_buy_level_roles: Optional[list] = None
    is_read_roles: Optional[list] = None
    is_select_user_users: Optional[list] = None
    contact_goods: Optional[list] = None
    is_hot_date: Optional[str] = None
    is_on_date: Optional[str] = None
    is_off_date: Optional[str] = None
    state: Optional[bool] = True
    tags: Optional[list] = None


    def update_dict(self):
        return self.model_dump(exclude_unset=True, exclude={"id"})

class BaseGoodsCategory(BaseModel):
    name: str = Field(..., description="分类名称", example="类目名称1")
    desc: Optional[str] = Field("", description="备注", example="备注1")
    order: int = Field(0, description="排序")
    parent_id: int = Field(0, description="父分类ID")
    attribute_ms_id: Optional[str] = Field("", description="描述属性ID")
    attribute_gg_id: Optional[str] = Field("", description="规格属性ID")
    cover: Optional[str] = Field("", description="封面")
    banner: Optional[str] = Field("", description="banner")


class GoodsCategoryCreate(BaseGoodsCategory):
    attribute_ms_id:Optional[list]= None
    attribute_gg_id: Optional[list] = None


class GoodsCategoryUpdate(BaseGoodsCategory):
    id: int
    attribute_ms_id: Optional[list] = None
    attribute_gg_id: Optional[list] = None

    def update_dict(self):
        return self.model_dump(exclude_unset=True, exclude={"id"})


class BaseGoodsAttribute(BaseModel):
    name: str = Field(..., description="名称", example="类目名称1")
    type: int = Field(1, description="属性类型1规则属性2描述属性")
    tags: Optional[str] = Field("", description="标签")


class GoodsAttributeCreate(BaseGoodsAttribute):
    tags:Optional[list]= None


class GoodsAttributeUpdate(BaseGoodsAttribute):
    id: int
    tags: Optional[list] = None
    def update_dict(self):
        return self.model_dump(exclude_unset=True, exclude={"id"})

class BaseGoodsBrand(BaseModel):
    name: str = Field(..., description="品牌名称", example="名称1")
    name_english: Optional[str] = Field("", description="品牌英文名称", example="english name1")
    cover: Optional[str] = Field("", description="封面", example="封面")
    logo_image: Optional[str] = Field("", description="logo图", example="logo图")
    share_image: Optional[str] = Field("", description="分享图", example="分享图")
    desc: Optional[str] = Field("", description="介绍", example="介绍")
    topic_id: Optional[int]  = Field(0, description="关联专题页id")


class GoodsBrandCreate(BaseGoodsBrand):
    ...

class GoodsBrandUpdate(BaseGoodsBrand):
    id: int
    def update_dict(self):
        return self.model_dump(exclude_unset=True, exclude={"id"})


class BaseGoodsExpress(BaseModel):
    name: str = Field(..., description="快递模板名称", example="名称1")
    type: int = Field(1)
    roles: Optional[str] = Field("")
    stop_roles: Optional[str] = Field("")


class GoodsExpressCreate(BaseGoodsExpress):
    roles: Optional[list] = None
    stop_roles: Optional[list] = None

class GoodsExpressUpdate(BaseGoodsExpress):
    id: int
    roles: Optional[list] = None
    stop_roles: Optional[list] = None
    def update_dict(self):
        return self.model_dump(exclude_unset=True, exclude={"id"})

class BaseGoodsSku(BaseModel):
    goods_id: int = Field(0)
    sku_name: str = Field(..., description="sku名称")
    sku_kc: int = Field(0)
    sku_price: float = Field(0.00)
    sku_cover: Optional[list] = None
    sku_level: Optional[list] = None
    can_do: int = Field(1)
    include: Any = None

class GoodsSkuCreate(BaseGoodsSku):
    ...

class GoodsSkuUpdate(BaseGoodsSku):
    id: int
    def update_dict(self):
        return self.model_dump(exclude_unset=True, exclude={"id"})

class BaseGoodsGroup(BaseModel):
    name: str = Field(..., description="名称")
    type: int = Field(1)
    times: int = Field(0)
    goods: Optional[list] = None
    goods_id: int = Field(0)
    sku_id: int = Field(0)
    type2: int = Field(1)

class GoodsGroupCreate(BaseGoodsGroup):
    goods: Optional[list] = None

class GoodsGroupUpdate(BaseGoodsGroup):
    id: int
    goods: Optional[list] = None
    def update_dict(self):
        return self.model_dump(exclude_unset=True, exclude={"id"})